import React, { Component } from 'react'
import PubSub from 'pubsub-js'
import Son from './Son'
import Son1 from './Son1'
export default class Far extends Component {
  componentDidMount() {
    //订阅
    this.subId = PubSub.subscribe('howFindMoney', (topic, data) => {
      console.log('far', data)
    })

    // localStorage.setItem('subId', this.subId)
  }

  componentWillUnmount() {
    // 组件卸载时,清除订阅
    PubSub.unsubscribe(this.subId)
  }
  render() {
    return (
      <div>
        Far
        <button
          onClick={() => {
            PubSub.publish('car', ['劳斯莱斯', '比亚迪'])
          }}
        >
          far的按钮,发布car话题
        </button>
        <Son></Son>
        <Son1></Son1>
      </div>
    )
  }
}
